/**
*      author: Y_Yao
*      created: 2024-11-09 23:48:24
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 7;
int n;

void solve()
{
    string s,r;
    cin >> n;
    int one = 0,zero = 0;
    cin >> s;
    for(int i = 0;i < n;i++)
    {
        if(s[i] == '0') zero++;
        else if(s[i] == '1') one++;
    }
    cin >> r;

    int cnt = 0;
    while(one != 0 && zero != 0 && cnt != n - 1)
    {
        one--;
        zero--;
        if(r[cnt] == '0') zero++;
        else if(r[cnt] == '1') one++;
        cnt++;
    }

    if(cnt == n - 1)
    {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}